package cn.jingyuan.fox.module.web.aop.feign;

import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author ChenJingyuan
 * @since 2024-11-23 13:17
 */
public abstract class FeignClientLogAbstractAspect {

    protected Logger log = LoggerFactory.getLogger(this.getClass());

    public abstract void pointcut();

    public Object exceptionAdvice(ProceedingJoinPoint joinPoint) {
        String targetName = null;
        Object[] args = null;

        try {
            targetName = joinPoint.getTarget().toString();
            args = joinPoint.getArgs();

            // fixme args
            log.debug("feign client exception advice, target={} , args={}", targetName, args);

            Object result;

            if (null == args) {
                result = joinPoint.proceed();
            } else {
                result = joinPoint.proceed(args);
            }

            return result;
        } catch (Throwable ex) {
            // fixme args
            log.error("feignClientExceptionAdvice, target={} , args={}", targetName, args, ex);

            throw new RuntimeException(ex);
        }
    }

}
